using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Reflection;
using System.IO;

namespace Pampa.Grid.Test
{
    public static class XmlHelper
    {
        public static XmlDocument GetXml(string name)
        {
            string assemblyName = "Pampa.Grid.Test";
            string path = "Xml";
            string fileName = assemblyName + "." + path + "." + name + ".xml";

            Assembly assembly = Assembly.Load(new AssemblyName(assemblyName));
            Stream stream = assembly.GetManifestResourceStream(fileName);

            XmlDocument doc = new XmlDocument();

            if (stream == null)
            {
                throw (new Pampa.CRUD.Exceptions.ConfigurationException("No se ha encontrado una definicion para " + name));
            }
            else
            {
                string content = string.Empty;
                using (System.IO.StreamReader sr = new System.IO.StreamReader(stream))
                {
                    content = sr.ReadToEnd();
                }

                doc.LoadXml(content);
            }

            return doc;
        }
    }
}
